<?php

class ShopItem {
	private $ID;
	private $ItemName;
	private $ItemShortDescription;
	private $ItemLongDescription;
	private $ItemImage;
	private $ItemCategoryID;
	private $ItemPrice;
	private $ItemDiscount;
	private $ItemCode;
	private $ItemAvalible;
	
	private $Controller;
	
	function __construct($ItemID, $Controller){
		$this->Controller = $Controller;
		
		$MySQL = $this->Controller->UseApps["mysql"];
		
		$SelectItem = $MySQL->query("SELECT * FROM {$MySQL->getPrefix()}shop_items WHERE id = $ItemID");
		
		if(mysql_num_rows($SelectItem) <= 0){
			return false;
		}
		
		$FetchItem = mysql_fetch_assoc($SelectItem);
		
		$this->ID = $FetchItem["id"];
		$this->ItemName = $FetchItem["item_name"];
		$this->ItemShortDescription = $FetchItem["item_short_description"];
		$this->ItemLongDescription = $FetchItem["item_long_description"];
		$this->ItemImage = $FetchItem["item_image"];
		$this->ItemCategoryID = $FetchItem["category_id"];
		$this->ItemPrice = $FetchItem["item_price"];
		$this->ItemDiscount = $FetchItem["item_discount"];
		$this->ItemCode = $FetchItem["item_code"];
		$this->ItemAvalible = ($FetchItem["item_avalible"] == "true") ? true : false;
	}
	
	function getID(){
		return $this->ID;
	}
	
	function getName(){
		return $this->ItemName;
	}
	
	function getShortDescription(){
		return $this->ItemShortDescription;
	}
	
	function getLongDescription(){
		return $this->ItemLongDescription;
	}
	
	function getImage(){
		$URL = Core::$FMSConfig->getValue("environment", "url");
		return $URL."content/shop/".$this->ItemImage;
	}
	
	function getCategoryID(){
		return $this->ItemCategoryID;
	}
	
	function getRawPrice(){
		return $this->ItemPrice;
	}
	
	function getDiscount(){
		return $this->ItemDiscount;
	}
	
	function getDiscountPrice(){
		$NewPrice = ($this->getDiscount() == 0) ? $this->getRawPrice() : $this->getRawPrice() - ($this->getRawPrice() * $this->getDiscount() / 100); 
		
		return round($NewPrice, 2);
	}
	
	function getCode(){
		return $this->ItemCode;
	}
	
	function getAvalibility(){
		return ($this->ItemAvalible == true) ? true : false;
	}
}

?>